package com.yonyou.pmclouds.basecom.async;

import com.yonyou.pmclouds.async.AsyncTaskPusher;
import org.springframework.transaction.support.TransactionSynchronizationAdapter;

/**
 * 异步调用信息推送入执行器的事务同步器，
 * <br/>通过使用spring-tx的事务同步器在事务结束后，将执行任务推送
 */
public class AsyncInfoTransactionSynchronization extends TransactionSynchronizationAdapter {
    private AsyncTaskPusher pusher;
    private AsyncInvocationInfo info;

    public AsyncInfoTransactionSynchronization(AsyncTaskPusher pusher, AsyncInvocationInfo info) {

        this.pusher = pusher;
        this.info = info;
    }

    @Override
    public void afterCompletion(int status) {
        if (status == STATUS_COMMITTED) {
            pusher.pushToExecutorQueue(info);
        }
    }
}
